#include "G4Util.hh"

#include "G4Step.hh"
#include "G4StepPoint.hh"
#include "G4TouchableHistory.hh"
//#include "MyMacros.hh"

G4int G4Util::GetLinearIdx(G4Step* step, G4int Ni, G4int Nj, G4int Nk)
{
    //MYG4TID(tid);
    G4StepPoint* preStep = step->GetPreStepPoint();
    auto* const th = (G4TouchableHistory*)(preStep->GetTouchable());
    // indexDepth 默认为 0
    // 对于 box, 深度 2 1 0 给出 x y z
    // 对于 cylinder即 G4Tubs, 深度 2 1 0 给出 Z phi R
    const auto idX = th->GetReplicaNumber(2);
    const auto idY = th->GetReplicaNumber(1);
    const auto idZ = th->GetReplicaNumber(0);
    //DINFOLN("[tid {} PSS/Hits]id1={}, id2={}, id3={}", tid, idX, idY, idZ);

    return idX * Nj * Nk + idY * Nk + idZ;
}